<template>
  <el-container class="app-container" v-loading="loading">
    <el-header style="height: auto">
      <el-form
        ref="form"
        :model="queryform"
        :inline="true"
        label-width="80px"
        size="small "
        class="search-form-inline"
      >
       <el-form-item label="案件接警号:" label-width="120px">
           <el-input v-model="queryform.jNum" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="涉案人身份证:" label-width="120px">
          <el-input v-model="queryform.sfzh" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="状态:">
          <el-select  v-model="queryform.status" placeholder="--请选择--">
              <el-option label="全部" :value="-1"> </el-option>
              <el-option label="对比成功" :value="1"> </el-option>
              <el-option label="完成认证" :value="2"> </el-option>
              <el-option label="排除" :value="3"> </el-option>
          </el-select>
        </el-form-item>
         <el-form-item label="比对成功时间:" label-width="120px">
          <CuDatepicker @update-date="updatedate" :def="false" :value-format="'yyyyMMddHHmmss'"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handlequery"
            >查 询</el-button
          >
        </el-form-item>
        <el-form-item style="float:right;">
         <el-button @click="exportSelected" type="primary">导出选中{{multipleSelection.length}}记录</el-button>
          <el-button @click="exportFun" type="primary">导出</el-button>
        </el-form-item>
      </el-form>
    </el-header>
    <el-main class="main-data-table">
        <DynamicTable :columns="tableColumns" :list="tableData" :current-page="currentPage" ref="singleTable" @selection-change="handleSelectionChange" :class-name="tableRowClassName">
            <template slot="top">
                <el-table-column type="selection" width="55" > </el-table-column>
            </template>
            <template slot="end">
                <el-table-column label="比对时间" align="center" :min-width="160">
                    <template slot-scope="scope">
                        <CuPopover
                                :data="scope.row.updateTime|StrToDate"
                                align="center"
                        >
                        </CuPopover>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="200">
                    <template slot-scope="scope">
                        <el-row v-if="scope.row.status==2||scope.row.status==3">
                            <el-button type="text" size="small" disabled
                            >认证</el-button>
                            <span class="vertical">|</span>
                            <el-button
                                    type="text"
                                    size="small"
                                    disabled
                            >排除</el-button
                            >
                        </el-row>
                        <el-row v-else>
                            <el-button type="text" size="small" @click="handleAuth(scope.row)"
                            >认证</el-button>
                            <span class="vertical">|</span>
                            <el-button
                                    type="text"
                                    size="small"
                                    @click="handleExclude(scope.row)"
                            >排除</el-button
                            >
                        </el-row>
                    </template>
                </el-table-column>
            </template>
        </DynamicTable>
    </el-main>
    <el-footer>
      <div class="pagination">
        <CustomPage
          :currentPage="currentPage"
          :pageSize="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </el-footer>
  </el-container>
</template>

<script>
import CustomPage from '@/common/CustomPageMin';
import CuPopover from '@/common/CuPopover';
import CuDatepicker from '@/common/CuDatepicker';
// import $ from 'jquery'
import DynamicTable from '@/common/DynamicTable';

export default {
  components: {
    CustomPage,
    CuDatepicker,
    CuPopover,
    DynamicTable
  },
  data() {
    return {
      loading: false,
      tableHeight: null,
      queryform: {
        jNum: '',
        sfzh: '',
        status: -1,
        beginTime: '',
        endTime: ''
      },
      multipleSelection: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      tableColumns: [
        {
          field: 'sfzh',
          title: '队列比中身份证号',
          width: '120px',
        },
        {
          field: 'jinId',
          title: '串并案中案件编号',
          width: '120px',
        },
        {
          field: 'successCondition',
          title: '比对成功条件',
          type: 'textarea',
          width: '180px',
        }
      ],
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.loadData();
      this.tableHeight = this.$refs['singleTable'].$el.clientHeight;
    });
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (row.status == 2) {
        return 'auth-row';
      } else if (row.status == 3) {
        return 'exclude-row';
      }
      return '';
    },
    updatedate(v) {
      this.queryform.beginTime = v[0];
      this.queryform.endTime = v[1];
    },
    handleUpload() {
      this.$refs['upload'].show();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // handleCancel(row) {
    //   this.$set(row, 'status', null);
    // },
    handleAuth(row) {
      this.$confirm('确定完成认证吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.updateStatus(row, 2);
        })
        .catch(() => {});
    },
    handleExclude(row) {
      this.$confirm('确定要排除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.updateStatus(row, 3);
        })
        .catch(() => {});
    },
    exportSelected() {
      if (this.multipleSelection.length===0) {
        this.$message.warning({
          showClose: true,
          message: '至少选择一条数据！',
        });
        return;
      }
      var html = '';
      let url = APIObj.apiUrl + '/clueQueue/exportSelected';

      var form = document.createElement('form');
      form.setAttribute('method', 'POST');
      form.setAttribute('action', url);
      var $form = $(form);
      this.multipleSelection.forEach(item => {
        html +=
          '<input type=\'hidden\' name="ids" value=\'' + item + '\'/>';
      });

      $form.append(html).appendTo('body');
      form.submit();
      $(form).remove();
    },
    exportFun() {
      var html = '';
      let url = APIObj.origin + '/clueQueue/exportDl';
      var obj = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        ...this.queryform,
      };

      var form = document.createElement('form');
      form.setAttribute('method', 'POST');
      form.setAttribute('action', url);
      var $form = $(form);
      for (var k in obj) {
        html +=
          '<input type=\'hidden\' name=\'' + k + '\' value=\'' + obj[k] + '\'/>';
      }
      $form.append(html).appendTo('body');
      form.submit();
      $(form).remove();
    },
    updateStatus(row, status) {
      this.loading = true;
      this.$axiosInstance({
        method: 'post',
        url: '/clueQueue/updateClueQueueById',
        params: {
          id: row.id,
          status
        },
      })
        .then((res) => {
          let { code, data } = res.data;
          if (code === 200) {
            this.loadData();
          }
          this.loading = false;
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    loadData() {
      this.loading = true;
      this.$axiosInstance({
        method: 'post',
        url: '/clueQueue/findDlResultAll',
        params: {
          pageNo: this.currentPage,
          pageSize: this.pageSize,
          ...this.queryform,
        },
      })
        .then((res) => {
          let { code, data } = res.data;
          if (code === 200) {
            this.tableData = data.dataInfo;
            this.total = data.resultCount;
          }
          this.loading = false;
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    handlequery() {
      this.currentPage = 1;
      this.loadData();
    },
    handleSizeChange(size) {
      this.currentPage = 1;
      this.pageSize = size;
      this.loadData();
    },
    handleCurrentChange(page) {
      this.currentPage = page;
      this.loadData();
    },
  },
  filters: {
    StrToDate(str) {
      if (str) {
        var nstr =
          str.substr(0, 4) +
          '-' +
          str.substr(4, 2) +
          '-' +
          str.substr(6, 2) +
          ' ' +
          str.substr(8, 2) +
          ':' +
          str.substr(10, 2) +
          ':' +
          str.substr(12, 2);
        return nstr;
      } else {
        return '-';
      }
    },
  },
};
</script>

<style lang="less" scoped>
.custom-table {
  /deep/ .el-table__body-wrapper {
    .auth-row {
      // background: rgba(79, 174, 206, 0.3);
      box-shadow: inset 0 0 20px 0 rgb(0 128 221);
    }
    .exclude-row {
      // background: #ccc;
      box-shadow: inset 0 0 20px 0 rgb(140, 141, 141);
    }
  }
}
</style>
